<?php
session_start();
require_once "includes/config.php";
	
	$date=date("Y-m-d");
	$sessid=session_id();
	
	$sqlSelItemUser="select * from tbl_items where item_id='".$_GET['id']."'";
	$rstSelItemUser=mysql_query($sqlSelItemUser);
	$rowSelItemUser=mysql_fetch_array($rstSelItemUser);
	if(is_array($rowSelItemUser))
	{
		$prod_id=$rowSelItemUser['product_id'];
		
		$sqlSelItemUser1="select * from tbl_items_code where product_id='".$prod_id."' and isSold='0' limit 0,1";
		$rstSelItemUser1=mysql_query($sqlSelItemUser1);
		$rowSelItemUser1=mysql_fetch_array($rstSelItemUser1);
		if(is_array($rowSelItemUser1))
		{
			$code=$rowSelItemUser1['code'];
		}
		
		$sqlSelprod="select * from tbl_product where product_id='".$prod_id."'";
		$rstSelprod=mysql_query($sqlSelprod);
		$rowSelprod=mysql_fetch_array($rstSelprod);
		if(is_array($rowSelprod))
		{
			$localPickup=$rowSelprod['localPickup'];
			
			if($localPickup==1)
			{
				$is_online=0;
			}
			else
			{
				$is_online=1;
			}
		}
		
		
		
		$sqlState="select * from tbl_users where user_id='".$_SESSION['user_id_sess']."'";
		$rstState=mysql_query($sqlState);
		$rowState=mysql_fetch_array($rstState);
		if(is_array($rowState))
		{
			$state_name=$rowState['state'];
			$sqlState="select * from tbl_state where statename='".$state_name."'";
			$rstState=mysql_query($sqlState);
			$rowState=mysql_fetch_array($rstState);
			if(is_array($rowState))
			{
				$state_id=$rowState['stateid'];
			}				
		}		
		/*$sqlSaleTax="select * from tbl_sale_tax where state_id='".$state_id."' and product_id='$prod_id'";
		$rstSaleTax=mysql_query($sqlSaleTax);
		$rowSaleTax=mysql_fetch_array($rstSaleTax);
		
		if(is_array($rowSaleTax))
		{
			$sales_tax=$rowSaleTax['sale_tax_amt'];
		}*/
		$sqlSaleTax="select * from tbl_product where product_id='$prod_id'";
		$rstSaleTax=mysql_query($sqlSaleTax) or die(mysql_error());
		$rowSaleTax=mysql_fetch_array($rstSaleTax);
		$sales_tax=$rowSaleTax['sales_tax'];
		$prod_name=stripslashes($rowSaleTax['product_name']);
		//echo $prod_name;
		
	}
	//echo "session".$_SESSION['user_type_sess'];
	if(!empty($_SESSION['user_id_sess']))
	{
	  $user_id=$_SESSION['user_id_sess'];
	}
	else
	{
	  $user_id=0;
	}
	//echo "insert into tempcart(itemid,itemname,itemamt,session_id,adddate,qty,shipping) values('".$_GET['id']."','".$_GET['name']."','".$_GET['amt']."','".$sessid."','".$date."','1')";	
	mysql_query("insert into tempcart(itemid,itemname,itemamt,session_id,adddate,qty,shipping,sales_tax,item_code,is_online,user_id) values('".$_GET['id']."','".$prod_name."','".$_GET['amt']."','".$sessid."','".$date."','1','".$_GET['shipping']."','".$sales_tax."','$code','$is_online','$user_id')");
	//echo "insert into tempcart(itemid,itemname,itemamt,session_id,adddate,qty,shipping,sales_tax,item_code,is_online,user_id) values('".$_GET['id']."','".$prod_name."','".$_GET['amt']."','".$sessid."','".$date."','1','".$_GET['shipping']."','".$sales_tax."','$code','$is_online','$user_id')";
	//exit;
	?>
	<script language="javascript1.2">
	window.location.href="index.php?cart";
	</script>